package com.he.eduservice.controller;


import com.he.commonutils.R;
import com.he.eduservice.entity.EduVideo;
import com.he.eduservice.entity.VideoInfoForm;
import com.he.eduservice.service.EduVideoService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author testhejinyu
 * @since 2021-06-02
 */
@RestController
@RequestMapping("/eduservice/video")
@CrossOrigin
public class EduVideoController {

    //小节的增删改查
    @Autowired
    EduVideoService videoService;

    @ApiOperation(value = "新增课时")
    @PostMapping("/addVideo")
    public R addVideo(
            @ApiParam(name = "videoInfoForm", value = "课时对象", required = true)
            @RequestBody VideoInfoForm videoInfoForm){
        videoService.addVideo(videoInfoForm);
        return R.ok();
    }

    @ApiOperation(value = "根据小节id查找课时")
    @GetMapping("/findVideoById/{id}")
    public R findVideoById(@PathVariable String id){
        EduVideo eduVideo = videoService.findVideoById(id);
        return R.ok().data("eduVideo",eduVideo);
    }


    @ApiOperation(value = "修改课时")
    @PostMapping("/updateVideo")
    public R updateVideo(
            @ApiParam(name = "videoInfoForm", value = "课时对象", required = true)
            @RequestBody VideoInfoForm videoInfoForm){
        videoService.updateVideo(videoInfoForm);
        return R.ok();
    }

    @ApiOperation(value = "删除课时")
    @DeleteMapping("/deleteVideo/{id}")
    public R deleteVideo(@PathVariable String id){
        videoService.deleteVideo(id);
        return R.ok();
    }


}

